AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )

include('shared.lua')

function ENT:OnRemove()
end

function ENT:Initialize()
	self.Entity:SetModel("models/buildingblocks/2d_1_2.mdl")
	self.Entity:PhysicsInit( SOLID_VPHYSICS )
	self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
	self.Entity:SetSolid( SOLID_VPHYSICS )
	
	local phys = self.Entity:GetPhysicsObject()
	if (phys:IsValid()) then
		phys:EnableMotion(true)
		phys:Wake()
	end
	
	self.leeches = {}
end

function ENT:Use()
end

function ENT:Think()
	for pl,type in pairs(self.leeches) do
		if pl:Alive() and (pl:GetPos()-self.Entity:GetPos()):Length() < 96 then
			if type == 1 then
				if pl:Health() < 100 then
					pl:SetHealth(pl:Health()+1)
				elseif pl:Armor() < 100 then
					pl:SetArmor(pl:Armor()+1)
				else
					self.leeches[pl] = nil
				end
			elseif type == 2 then
				if gmod.GetGamemode().geof.rounds[gmod.GetGamemode().geof.round.cur].weapons == 2 then
					local pri = {gmod.GetGamemode().geof.players[plid].pri}
					local sec = {gmod.GetGamemode().geof.players[plid].sec}
					pri[2] = weapons.Get(pri[1]).Primary.Ammo
					sec[2] = weapons.Get(sec[1]).Primary.Ammo
					pri[3] = pl:GetAmmoCount(pri[2])
					sec[3] = pl:GetAmmoCount(sec[2])
					if pri[3] < 50 then
						pl:GiveAmmo(1,pri[2])
					elseif sec[3] < 50 then
						pl:GiveAmmo(1,sec[2])
					else
						self.leeches[pl] = nil
					end
				end
			end
		else
			self.leeches[pl] = nil
		end
	end
end

function ENT:UpdateTransmitState()
	return TRANSMIT_PVS
end
